package com.hyg.lib_music.util;

import com.hyg.lib_common.Base.BaseApplication;
import com.hyg.lib_music.presenter.di.components.ApplicationComponent;
import com.hyg.lib_music.presenter.di.components.DaggerApplicationComponent;
import com.hyg.lib_music.presenter.di.modules.ApplicationModule;

/**
 * @author: visitant
 * @date: 2020/12/21
 */
public class ApplicationComponentUtil {
    public static ApplicationComponent mApplicationComponent;
    public static BaseApplication application;

    public ApplicationComponentUtil(BaseApplication application) {
        this.application = application;
        if (mApplicationComponent == null) {
            register(application);
        }
    }

    /**
     * 获取 ApplicationComponent
     *
     * @return
     */
    public  ApplicationComponent getApplicationComponent() {
        return mApplicationComponent;
    }

    public ApplicationComponent getComponent() {
        return mApplicationComponent;
    }

    public static void register(BaseApplication application) {
        //Dagger注入
        mApplicationComponent = DaggerApplicationComponent.builder()
                .applicationModule(new ApplicationModule(application))
                .build();
        mApplicationComponent.inject(application);
    }

}
